package com.wn.controller;

import com.wn.annotation.RequireRoles;
import com.wn.entity.Hotelinfo;
import com.wn.entity.Order;
import com.wn.service.OrderService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (Order)表控制层
 *
 * @author makejava
 * @since 2020-10-26 09:32:12
 */
@RestController
@RequestMapping("order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    /**
     * 通过主键查询单条数
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("查询订单")
    public Order selectOne(String id) {

        return this.orderService.queryById(id);
    }

    /**
     *分页查询订单数据
     *
     * @return 单条数据
     */
    @SystemControllerLog(description = "分页查询订单列表")
    @PostMapping("searchSomeOrderByPage")
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    @RequireRoles(roles = {"admin","super_admin","reception","guide"},index = 1)
    public Rsp searchSomeOrderByPage(@RequestBody PageParam<Order> pageParam
                                     ,@RequestHeader("token") String token) {

        return Rsp.success(orderService.queryAllByLimit(pageParam));


    }
    /**
     *增加单个数据，下单
     *
     * @param order 订单
     * @return 单条数据
     */
    @SystemControllerLog(description = "添加订单信息")
    @PostMapping("addOneOrder")
    @ApiOperation("增加数据")
    @RequireRoles(roles = {"tourist","admin","super_admin","reception","guide"},index = 1)
    public Rsp addOneOrder(@RequestBody @Valid Order order,
                           @RequestHeader("token") String token)
    {
        return Rsp.success(orderService.insert(order));

    }

    /**
     *预下单
     *
     * @param order 订单
     * @return 单条数据
     */
    @SystemControllerLog(description = "用户预下单订单信息")
    @PostMapping("bookOrder")
    @ApiOperation("用户预下单数据")
    @RequireRoles(roles = {"tourist","admin","super_admin","reception","guide"},index = 1)
    public Rsp bookOrder(@RequestBody @Valid Order order,
                         @RequestHeader("token") String token)
    {
        return orderService.createOrder(order);
    }


    /**
     *修改单个数据
     * @param order 订单
     * @return 单条数据
     */
    @SystemControllerLog(description = "修改订单信息")
    @PostMapping("updateOrder")
    @ApiOperation("修改单条数据")
    @RequireRoles(roles = {"super_admin","admin","tourist"},index = 1)
    public Rsp updateOrder(@RequestBody @Valid Order order,@RequestHeader("token") String token)
    {

        return Rsp.success(orderService.update(order));

    }

    /**
     *逻辑删除单个数据
     *
     *
     * @return 单条数据
     */
    @PostMapping("deleteupdateOrderLogical")
    @ApiOperation("逻辑删除单条数据")
    @RequireRoles(roles = {"super_admin","admin"},index = 1)
    public Rsp deleteupdateOrderLogical(@RequestBody Order order,@RequestHeader("token") String token)
    {

        return Rsp.success(orderService.deleteLogical(order.getId()));

    }


    @PostMapping("queryOrderStatusFromDB")
    @ApiOperation("根据订单编号查询订单")
    public Rsp queryOrderStatusFromDB(@RequestBody Order order){
        return orderService.queryOrderStatusFromDB(order.getOrderno());
    }


    @PostMapping("searchSomeOrderByUserid")
    @ApiOperation("根据userid查询订单")
    public Rsp searchSomeOrderByUserid(@RequestBody Order order){
        return orderService.searchSomeOrderByUserid(order.getCreateuserid());
    }

}
